package logic

import (
	"context"
	"doctor-medicine-system/doctorrpc/doctorrpc"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineAddApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMedicineAddApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineAddApiLogic {
	return &MedicineAddApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MedicineAddApiLogic) MedicineAddApi(req *types.MedicineAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.DoctorRpc.MedicineAdd(l.ctx, &doctorrpc.MedicineAddRequest{
		Name:  req.Name,
		Stock: req.Stock,
		Class: req.Class,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "药品添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
